package org.opens.mybatisplus.controller.enumObj3;

import org.opens.mybatisplus.entity.enumObj3.EnumObj3;
import org.opens.mybatisplus.service.EnumObj3.EnumObj3Service;
import org.opens.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping(value = "/api/mybatis")
@CrossOrigin(origins = "*", maxAge = 3600, allowCredentials = "true")
public class EnumObj3Controller {

    @Autowired
    private EnumObj3Service enumObj3Service;

    /**
     * 说明:
     *      1. 获取资源
     */
    @GetMapping(value = "/enum/{id}")
    public R findById(
            @PathVariable(value = "id") Integer id
    ) {
        R ok = R.success("ok");
        EnumObj3 enumObj3 = enumObj3Service.findById(id);
        ok.put("data", enumObj3);
        return ok;
    }

    /**
     * 说明:
     *      1. 新增资源
     */
    @PostMapping(value = "/enum")
    public R save(
            @RequestBody EnumObj3 enumObj3
    ) {
        R ok = R.success("ok");
        enumObj3Service.saveOrUpdate(enumObj3, false);
        ok.put("data", enumObj3);
        return ok;
    }

    /**
     * 说明:
     *      1. 资源部分更新
     */
    @PatchMapping(value = "/enum")
    public R update(
            @RequestBody EnumObj3 enumObj3
    ) {
        R ok = R.success("ok");
        enumObj3Service.saveOrUpdate(enumObj3, false);
        ok.put("data", enumObj3);
        return ok;
    }

    /**
     * 说明:
     *      1. 资源全量更新
     */
    @PutMapping(value = "/enum")
    public R fullUpdate(
            @RequestBody EnumObj3 enumObj3
    ) {
        R ok = R.success("ok");
        enumObj3Service.saveOrUpdate(enumObj3, true);
        ok.put("data", enumObj3);
        return ok;
    }

    /**
     * 说明:
     *      1. 资源删除
     */
    @DeleteMapping(value = "/enum/{id}")
    public R deleteById(
            @PathVariable Integer id
    ) {
        R ok = R.success("删除成功");
        enumObj3Service.deleteById(id);
        return ok;
    }

}
